package main

import "fmt"

func main() {

	var writer DataWriter = new(file)
	//file必须实现全部方法
	writer.WriteData("data")
	writer.CanWrite()
}

type DataWriter interface {
	WriteData(data interface{}) error
	CanWrite() bool
}

type file struct {
}

//file实现DataWriter接口的WriteData方法
func (f *file) WriteData(data interface{}) error {
	fmt.Println("WriteData:", data)
	return nil
}

//file实现DataWriter接口的CanWrite方法
func (f *file) CanWrite() bool {
	fmt.Println("can")
	return true
}
